package runInfo;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;
//import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Hashtable;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
//import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
//import org.eclipse.swt.widgets.Composite;
//import org.jfree.experimental.cBar.swt.ChartComposite;

//import org.eclipse.swt.SWT;
//import org.eclipse.swt.widgets.Composite;
//import org.eclipse.ui.part.ViewPart;
//import org.jfree.cBar.ChartFactory;
//import org.jfree.cBar.JFreeChart;
//import org.jfree.cBar.plot.PiePlot;
//import org.jfree.data.general.DefaultPieDataset;
//import org.jfree.data.general.PieDataset;
//import org.jfree.experimental.cBar.swt.ChartComposite;


//import com.phidgets.TemperatureSensorPhidget;

//import runInfo.Data;
//import runInfo.mainGui.MeasurementLoop;
//import org.eclipse.swt.custom.ScrolledComposite;
//import org.jfree.cBar.JFreeChart;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.browser.Browser;

public class TestThreadGUI implements Runnable {


    private Shell sShell = null;  //  @jve:decl-index=0:visual-constraint="97,44"
    static boolean headerFlag = true;
    public static boolean writeOut = false;

//    TemperatureSensorPhidget tempsensor;

//    public Label tcOut = null;
//    public static double tempC = 0.0;
//    public static double tempF = 0.0;
//    public static double tempAC = 0.0;
//    public static double tempAF = 0.0;
//    public static int bottling = 0;

    public static long t0;
    private Text text1 = null;
    private Text text11 = null;
    private Text text2 = null;
    private ProgressBar progressBar = null;
    private Text coltext11111 = null;
    private Button Plotbutton = null;
    private Text text12 = null;
    private Group Distgroup = null;
    private Text coltext113 = null;
    private Text coltext1113 = null;
    private Text coltext11112 = null;
    private Text corrBrixText = null;
    private Text potenAbvText = null;
    private Text coltext1 = null;
    private Group distGroup = null;
    private Text coltext11121 = null;
    private Text text111 = null;
    private Text coltext2 = null;
    private Text coltext112 = null;
    private Text coltext1112 = null;
    private Combo bottleCombo = null;
    static Combo boilerTempCombo = null;
    static Text measAbvText = null;
    static Combo distTempCombo = null;
    static Text corrAbvText = null;
    private Text coltext111121 = null;
    private Text coltext1111211 = null;
    private Group sensorGroup = null;
    private Text coltext = null;
    private Text coltextC = null;
    private Text temptextA = null;
    private Text temptextC1 = null;
    static Text temptextAC = null;
    static Text tempTextC = null;
    private Text coltextF = null;
    static Text temptextAF = null;
    static Text tempTextF = null;
    private Text temptextC11 = null;
    private Text temptextC111 = null;
    private Text temptextC1111 = null;
    private Button startButton = null;
    private Button stopButton = null;
    private Text coltext11 = null;
    private Text coltext12 = null;
    private Text coltext13 = null;
    private Text mashAbvText = null;
    private Combo OGcombo = null;
    private Combo TGcombo = null;
    private Combo ogTempCombo = null;
    private Combo tgTempCombo = null;
    private Text potenAbvText1 = null;
    private Browser Flotbrowser = null;
    private Combo timeSpanCombo = null;
    private Group plotGroup = null;
    private Button plotRefreshbutton = null;
    private Text text112 = null;
    private Text text121 = null;
    private static String timeSpan = "5 min";

    private void createSShell() {
        GridData gridData2 = new GridData();
        GridData gridData1 = new GridData();
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 5;
        sShell = new Shell();
        sShell.setText("Whiskey");
        sShell.setFont(new Font(Display.getDefault(), "Segoe UI", 18, SWT.NORMAL));
        sShell.setEnabled(true);
        sShell.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        sShell.setLayout(gridLayout);
        sShell.setSize(new Point(1128, 665));
        createDistgroup();
        createDistGroup();
        createSensorGroup();
        Label filler45 = new Label(sShell, SWT.NONE);
        Label filler9 = new Label(sShell, SWT.NONE);
        createFlotbrowser();
        createPlotGroup();
        text1 = new Text(sShell, SWT.NONE);
        String[] Items = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134"};
        boilerTempCombo.select(0);
        Label filler44 = new Label(sShell, SWT.NONE);
        Label filler3314 = new Label(sShell, SWT.NONE);
        String[] items = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"};
//		String[] items = {"1 C", "2 C", "3 C", "4 C", "5 C", "6 C", "7 C", "8 C", "9 C", "10 C", "11 C", "12 C", "13 C", "14 C", "15 C", "16 C", "17 C", "18 C", "19 C", "20 C", "21 C", "22 C", "23 C", "24 C", "25 C", "26 C", "27 C", "28 C", "29 C", "30 C", "31 C", "32 C", "33 C", "34 C", "35 C", "36 C", "37 C", "38 C", "39 C", "40 C", "41 C", "42 C", "43 C", "44 C", "45 C", "46 C", "47 C", "48 C", "49 C", "50 C"};
        distTempCombo.select(0);
        Label filler31 = new Label(sShell, SWT.NONE);
        Label filler7 = new Label(sShell, SWT.NONE);
        Label filler24 = new Label(sShell, SWT.NONE);
        Label filler81 = new Label(sShell, SWT.NONE);
        Label filler5 = new Label(sShell, SWT.NONE);
        Label filler10 = new Label(sShell, SWT.NONE);
        Label filler99 = new Label(sShell, SWT.NONE);
        text1.setEditable(false);
        text1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        text1.setEnabled(false);
        text1.setText("   ");
        Label filler3 = new Label(sShell, SWT.NONE);
        Label filler124 = new Label(sShell, SWT.NONE);
        Label filler12 = new Label(sShell, SWT.NONE);
        Label filler2 = new Label(sShell, SWT.NONE);
        Label filler141 = new Label(sShell, SWT.NONE);
        Label filler142 = new Label(sShell, SWT.NONE);
        Label filler1 = new Label(sShell, SWT.NONE);
        Label filler339 = new Label(sShell, SWT.NONE);
        text121 = new Text(sShell, SWT.NONE);
        text121.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        text121.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text121.setEditable(false);
        text121.setText("     ");
        text121.setEnabled(false);
        Label filler3315 = new Label(sShell, SWT.NONE);
        Label filler14 = new Label(sShell, SWT.NONE);
        Label filler16 = new Label(sShell, SWT.NONE);
        Label filler22 = new Label(sShell, SWT.NONE);
        Label filler23 = new Label(sShell, SWT.NONE);
        text11 = new Text(sShell, SWT.NONE);
        text11.setText("Set Time Span to Plot:");
        text11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        text11.setEditable(false);
        text11.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text11.setEnabled(false);
        Label filler25 = new Label(sShell, SWT.NONE);
        Label filler30 = new Label(sShell, SWT.NONE);
        Label filler32 = new Label(sShell, SWT.NONE);
        Label filler34 = new Label(sShell, SWT.NONE);
        coltext11111 = new Text(sShell, SWT.NONE);
        coltext11111.setEditable(false);
        coltext11111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext11111.setText("Ph Temp adjustment");
        coltext11111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext11111.setEnabled(false);
        Label filler37 = new Label(sShell, SWT.NONE);
        Label filler38 = new Label(sShell, SWT.NONE);
        Label filler40 = new Label(sShell, SWT.NONE);
        Label filler42 = new Label(sShell, SWT.NONE);
        text2 = new Text(sShell, SWT.NONE);
        text2.setText("information updating..............                                                                                                      ");
        text2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        text2.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text2.setLayoutData(gridData1);
        text2.setEnabled(false);
        Label filler11 = new Label(sShell, SWT.NONE);
        Label filler15 = new Label(sShell, SWT.NONE);
        Label filler28 = new Label(sShell, SWT.NONE);
        Label filler333 = new Label(sShell, SWT.NONE);
        Plotbutton = new Button(sShell, SWT.NONE);
        Plotbutton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        Plotbutton.setText("Plot Data");
        Label filler335 = new Label(sShell, SWT.NONE);
        Label filler336 = new Label(sShell, SWT.NONE);
        Label filler337 = new Label(sShell, SWT.NONE);
        progressBar = new ProgressBar(sShell, SWT.NONE);
        progressBar.setLayoutData(gridData2);
        text12 = new Text(sShell, SWT.NONE);
        text12.setEnabled(false);
        text12.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text12.setEditable(false);
        text12.setText("Plot - abv - bottle");
        text12.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        Plotbutton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
//				JFreeChart cBar = Plot.CreateChart(tempTCArr,timeS,bottle,boilerTemp);
//				ChartComposite frame = new ChartComposite(scrolledComposite, SWT.NONE, cBar, true);
//				Plot.CreateChart(tempTCArr,timeS,bottle,boilerTemp);
                Plot.CreateChart();
//				scrolledComposite.setBackground(cBar);
            }
        });
        distTempCombo.select(0);
        boilerTempCombo.select(0);
        bottleCombo.select(0);
        OGcombo.select(32);
        TGcombo.select(2);
        tgTempCombo.select(25);
        ogTempCombo.select(29);
    }


    public static String CurrentTime() {
        Calendar calendar = new GregorianCalendar();
        String am_pm;
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int hour = calendar.get(Calendar.HOUR);
        int minute = calendar.get(Calendar.MINUTE);
        int second = calendar.get(Calendar.SECOND);
        if (calendar.get(Calendar.AM_PM) == 0)
            am_pm = "AM";
        else {
            hour = hour + 12;
            am_pm = "PM";
        }
//      	String times = year + "-" + month  + "-" +day + "\t" + hour + ":"+ minute + ":" + second + " " + am_pm;
//      	String times = year + "-" + month  + "-" +day + " " + hour + ":"+ minute + ":" + second;
        Data.dateTimeS = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

        return Data.dateTimeS;
    }

    //
//	@Override
    public void run() {
        Display display = Display.getDefault();
        TestThreadGUI thisClass = new TestThreadGUI();
        thisClass.createSShell();
        thisClass.sShell.open();

        while (!thisClass.sShell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();

    }

    private void createDistgroup() {
        GridLayout gridLayout1 = new GridLayout();
        gridLayout1.numColumns = 8;
        Distgroup = new Group(sShell, SWT.NONE);
        Distgroup.setText("Fermenting Data");
        Distgroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        Distgroup.setLayout(gridLayout1);
        coltext1 = new Text(Distgroup, SWT.NONE);
        coltext1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext1.setEditable(false);
        coltext1.setText("OG Temperature");
        coltext1.setEnabled(false);
        createOgTempCombo();
        Label filler469 = new Label(Distgroup, SWT.NONE);
        coltext11 = new Text(Distgroup, SWT.NONE);
        coltext11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext11.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext11.setEditable(false);
        coltext11.setText("OG");
        coltext11.setEnabled(false);
        createOGcombo();
        Label filler57 = new Label(Distgroup, SWT.NONE);
        Label filler72 = new Label(Distgroup, SWT.NONE);
        Label filler4614 = new Label(Distgroup, SWT.NONE);
        coltext113 = new Text(Distgroup, SWT.NONE);
        coltext113.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext113.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext113.setEditable(false);
        coltext113.setText("TG Temperature");
        coltext113.setEnabled(false);
        createTgTempCombo();
        Label filler4610 = new Label(Distgroup, SWT.NONE);
        coltext12 = new Text(Distgroup, SWT.NONE);
        coltext12.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext12.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext12.setEditable(false);
        coltext12.setText("TG");
        coltext12.setEnabled(false);
        createTGcombo();
        Label filler41 = new Label(Distgroup, SWT.NONE);
        Label filler68 = new Label(Distgroup, SWT.NONE);
        Label filler4613 = new Label(Distgroup, SWT.NONE);
        coltext1113 = new Text(Distgroup, SWT.NONE);
        coltext1113.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext1113.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext1113.setEditable(false);
        coltext1113.setText("   ");
        coltext1113.setEnabled(false);
        potenAbvText1 = new Text(Distgroup, SWT.NONE);
        potenAbvText1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        potenAbvText1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        potenAbvText1.setEditable(false);
        potenAbvText1.setText("  ");
        potenAbvText1.setEnabled(false);
        corrBrixText = new Text(Distgroup, SWT.NONE);
        corrBrixText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        corrBrixText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        corrBrixText.setEditable(false);
        corrBrixText.setText("  ");
        corrBrixText.setEnabled(false);
        Label filler4615 = new Label(Distgroup, SWT.NONE);
        Label filler3216 = new Label(Distgroup, SWT.NONE);
        Label filler39 = new Label(Distgroup, SWT.NONE);
        Label filler65 = new Label(Distgroup, SWT.NONE);
        Label filler71 = new Label(Distgroup, SWT.NONE);
        coltext11112 = new Text(Distgroup, SWT.NONE);
        coltext11112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext11112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext11112.setEditable(false);
        coltext11112.setText("  ");
        coltext11112.setEnabled(false);
        potenAbvText = new Text(Distgroup, SWT.NONE);
        potenAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        potenAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        potenAbvText.setEditable(false);
        potenAbvText.setText("  ");
        potenAbvText.setEnabled(false);
        Label filler27 = new Label(Distgroup, SWT.NONE);
        coltext13 = new Text(Distgroup, SWT.NONE);
        coltext13.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext13.setEditable(false);
        coltext13.setText("abv");
        coltext13.setEnabled(false);
        coltext13.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        mashAbvText = new Text(Distgroup, SWT.NONE);
        mashAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        mashAbvText.setEditable(false);
        mashAbvText.setText("000.00");
        mashAbvText.setEnabled(false);
        mashAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        Label filler64 = new Label(Distgroup, SWT.NONE);
        Label filler70 = new Label(Distgroup, SWT.NONE);
        Label filler4612 = new Label(Distgroup, SWT.NONE);
        coltext111121 = new Text(Distgroup, SWT.NONE);
        coltext111121.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext111121.setFont(new Font(Display.getDefault(), "Segoe UI", 12, SWT.NORMAL));
        coltext111121.setEditable(false);
        coltext111121.setText("    ");
        coltext111121.setEnabled(false);
        Label filler20 = new Label(Distgroup, SWT.NONE);
        Label filler26 = new Label(Distgroup, SWT.NONE);
        Label filler29 = new Label(Distgroup, SWT.NONE);
        Label filler35 = new Label(Distgroup, SWT.NONE);
        Label filler58 = new Label(Distgroup, SWT.NONE);
        Label filler69 = new Label(Distgroup, SWT.NONE);
        Label filler4611 = new Label(Distgroup, SWT.NONE);
        coltext1111211 = new Text(Distgroup, SWT.NONE);
        coltext1111211.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext1111211.setFont(new Font(Display.getDefault(), "Segoe UI", 12, SWT.NORMAL));
        coltext1111211.setEditable(false);
        coltext1111211.setText("   ");
        coltext1111211.setEnabled(false);
    }

    /**
     * This method initializes distGroup
     */
    private void createDistGroup() {
        GridLayout gridLayout2 = new GridLayout();
        gridLayout2.numColumns = 2;
        distGroup = new Group(sShell, SWT.NONE);
        distGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        distGroup.setText("Distilling Data");
        distGroup.setLayout(gridLayout2);
        coltext11121 = new Text(distGroup, SWT.NONE);
        coltext11121.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext11121.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext11121.setEditable(false);
        coltext11121.setText("Bottle #");
        coltext11121.setEnabled(false);
        createBottleCombo();
        text111 = new Text(distGroup, SWT.NONE);
        text111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        text111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text111.setEditable(false);
        text111.setText("boiler temp");
        text111.setEnabled(false);
        createBoilerTempCombo();
        coltext2 = new Text(distGroup, SWT.NONE);
        coltext2.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext2.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext2.setEditable(false);
        coltext2.setText("Measured abv");
        coltext2.setEnabled(false);
        measAbvText = new Text(distGroup, SWT.BORDER);
        measAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        measAbvText.setText("000.0");
        measAbvText.addModifyListener(new org.eclipse.swt.events.ModifyListener() {
            public void modifyText(org.eclipse.swt.events.ModifyEvent e) {
                if (Double.valueOf(boilerTempCombo.getText()) >= -1 &
                        Double.valueOf(measAbvText.getText()) >= -1 &
                        Double.valueOf(distTempCombo.getText()) >= -1 &
                        Double.valueOf(OGcombo.getText()) >= -1 &
                        Double.valueOf(tgTempCombo.getText()) >= -1 &
                        Double.valueOf(OGcombo.getText()) >= -1 &
                        Double.valueOf(TGcombo.getText()) >= -1 &
                        Double.valueOf(bottleCombo.getText()) >= -1
                        ) {
                    corrAbvText.setText(String.valueOf(TempCorrections.GetABV(Double.valueOf(measAbvText.getText()), distTempCombo.getText())));
                }

            }
        });
        coltext112 = new Text(distGroup, SWT.NONE);
        coltext112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext112.setEditable(false);
        coltext112.setText("Distillate Temp");
        coltext112.setEnabled(false);
        createDistTempCombo();
        coltext1112 = new Text(distGroup, SWT.NONE);
        coltext1112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext1112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext1112.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_FOREGROUND));
        coltext1112.setEditable(false);
        coltext1112.setText("Corrected abv");
        coltext1112.setEnabled(false);
        corrAbvText = new Text(distGroup, SWT.NONE);
        corrAbvText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        corrAbvText.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        corrAbvText.setEditable(false);
        corrAbvText.setText("000.00");
        corrAbvText.setEnabled(false);
    }

    /**
     * This method initializes bottleCombo
     */
    private void createBottleCombo() {
        bottleCombo = new Combo(distGroup, SWT.NONE);
        bottleCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        bottleCombo.setText("000");
        String[] bottleItems = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20"};
        bottleCombo.setItems(bottleItems);
        bottleCombo
                .addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
                    public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                        if (Double.valueOf(boilerTempCombo.getText()) >= -1 &
                                Double.valueOf(measAbvText.getText()) >= -1 &
                                Double.valueOf(distTempCombo.getText()) >= -1 &
                                Double.valueOf(OGcombo.getText()) >= -1 &
                                Double.valueOf(tgTempCombo.getText()) >= -1 &
                                Double.valueOf(OGcombo.getText()) >= -1 &
                                Double.valueOf(TGcombo.getText()) >= -1 &
                                Double.valueOf(bottleCombo.getText()) >= -1
                                ) {
                            Data.bottleS = bottleCombo.getText();
                        }
                    }

                    public void widgetDefaultSelected(
                            org.eclipse.swt.events.SelectionEvent e) {
                    }
                });
    }

    /**
     * This method initializes boilerTempCombo
     */
    private void createBoilerTempCombo() {
/*        if (Double.valueOf(boilerTempCombo.getText()) >= -1 &
                Double.valueOf(measAbvText.getText()) >= -1 &
                Double.valueOf(distTempCombo.getText()) >= -1 &
                Double.valueOf(OGcombo.getText()) >= -1 &
                Double.valueOf(tgTempCombo.getText()) >= -1 &
                Double.valueOf(OGcombo.getText()) >= -1 &
                Double.valueOf(TGcombo.getText()) >= -1 &
                Double.valueOf(bottleCombo.getText()) >= -1
                ) {*/
            boilerTempCombo = new Combo(distGroup, SWT.NONE);
            boilerTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
            String[] Items = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "108", "109", "110", "111", "112", "113", "114", "115", "116", "117", "118", "119", "120", "121", "122", "123", "124", "125", "126", "127", "128", "129", "130", "131", "132", "133", "134"};
            boilerTempCombo.setItems(Items);
            boilerTempCombo.setText("000");
//        }
    }

    private void createDistTempCombo() {
        distTempCombo = new Combo(distGroup, SWT.NONE);
        distTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50"};
        distTempCombo.setItems(Items);
        distTempCombo.setText("1.000");
        distTempCombo
                .addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
                    public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                        if (Double.valueOf(boilerTempCombo.getText()) >= -1 &
                                Double.valueOf(measAbvText.getText()) >= -1 &
                                Double.valueOf(distTempCombo.getText()) >= -1 &
                                Double.valueOf(OGcombo.getText()) >= -1 &
                                Double.valueOf(tgTempCombo.getText()) >= -1 &
                                Double.valueOf(OGcombo.getText()) >= -1 &
                                Double.valueOf(TGcombo.getText()) >= -1 &
                                Double.valueOf(bottleCombo.getText()) >= -1
                                ) {
                            corrAbvText.setText(String.valueOf(TempCorrections.GetABV(Double.valueOf(measAbvText.getText()), distTempCombo.getText())));
                        }
                    }

                    public void widgetDefaultSelected(
                            org.eclipse.swt.events.SelectionEvent e) {
                    }
                });
    }

    public static boolean isWriteOut() {
        return writeOut;
    }

    public static boolean isHeaderFlag() {
        return headerFlag;
    }

    public static void setHeaderFlag(boolean headerFlag) {
        TestThreadGUI.headerFlag = headerFlag;
    }

    private void createSensorGroup() {
        GridLayout gridLayout3 = new GridLayout();
        gridLayout3.numColumns = 4;
        sensorGroup = new Group(sShell, SWT.NONE);
        sensorGroup.setText("Temperature Sensor");
        sensorGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        sensorGroup.setLayout(gridLayout3);

        coltext = new Text(sensorGroup, SWT.NONE);
        coltext.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltext.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltext.setEditable(false);
        coltext.setText("Sensor");
        coltext.setEnabled(false);
        coltextC = new Text(sensorGroup, SWT.CENTER);
        coltextC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltextC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltextC.setEditable(false);
        coltextC.setText("C");
        coltextC.setEnabled(false);
        coltextF = new Text(sensorGroup, SWT.CENTER);
        coltextF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        coltextF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        coltextF.setEditable(false);
        coltextF.setText("F");
        coltextF.setEnabled(false);
        Label filler21 = new Label(sensorGroup, SWT.NONE);
        temptextA = new Text(sensorGroup, SWT.NONE);
        temptextA.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextA.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextA.setEditable(false);
        temptextA.setText("Board: ");
        temptextA.setEnabled(false);
        temptextAC = new Text(sensorGroup, SWT.NONE);
        temptextAC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextAC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextAC.setEditable(false);
        temptextAC.setText("000.000");
        temptextAC.setEnabled(false);
        temptextAF = new Text(sensorGroup, SWT.NONE);
        temptextAF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextAF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextAF.setEditable(false);
        temptextAF.setText("000.000");
        temptextAF.setEnabled(false);
        Label filler19 = new Label(sensorGroup, SWT.NONE);
        temptextC1 = new Text(sensorGroup, SWT.WRAP);
        temptextC1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextC1.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextC1.setEditable(false);
        temptextC1.setText("Thermocouple:    ");
        temptextC1.setEnabled(false);
        tempTextC = new Text(sensorGroup, SWT.NONE);
        tempTextC.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        tempTextC.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        tempTextC.setEditable(false);
        tempTextC.setText("000.000");
        tempTextC.setEnabled(false);
        tempTextF = new Text(sensorGroup, SWT.NONE);
        tempTextF.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        tempTextF.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        tempTextF.setEditable(false);
        tempTextF.setText("000.000");
        tempTextF.setEnabled(false);
        Label filler18 = new Label(sensorGroup, SWT.NONE);
        temptextC11 = new Text(sensorGroup, SWT.WRAP);
        temptextC11.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextC11.setFont(new Font(Display.getDefault(), "Segoe UI", 9, SWT.NORMAL));
        temptextC11.setEditable(false);
        temptextC11.setText("   ");
        temptextC11.setEnabled(false);
        Label filler = new Label(sensorGroup, SWT.NONE);
        Label filler4 = new Label(sensorGroup, SWT.NONE);
        Label filler17 = new Label(sensorGroup, SWT.NONE);
        startButton = new Button(sensorGroup, SWT.NONE);
        startButton.setText("Start Recording");
        startButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        startButton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        startButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                writeOut = true;
            }
        });
        temptextC111 = new Text(sensorGroup, SWT.WRAP);
        temptextC111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextC111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextC111.setEditable(false);
        temptextC111.setText("  ");
        temptextC111.setEnabled(false);
        Label filler6 = new Label(sensorGroup, SWT.NONE);
        Label filler8 = new Label(sensorGroup, SWT.NONE);
        stopButton = new Button(sensorGroup, SWT.NONE);
        stopButton.setText("Stop Recording");
        stopButton.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        stopButton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        stopButton.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                writeOut = false;
            }
        });
        temptextC1111 = new Text(sensorGroup, SWT.WRAP);
        temptextC1111.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        temptextC1111.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        temptextC1111.setEditable(false);
        temptextC1111.setText("  ");
        temptextC1111.setEnabled(false);
    }

    private void createOGcombo() {
        OGcombo = new Combo(Distgroup, SWT.NONE);
        OGcombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"1.000", "1.002", "1.005", "1.007", "1.010", "1.012", "1.015", "1.017", "1.020", "1.022", "1.025", "1.0275", "1.030", "1.032", "1.035", "1.037", "1.040", "1.042", "1.045", "1.047", "1.050", "1.052", "1.055", "1.057", "1.060", "1.062", "1.065", "1.067", "1.070", "1.072", "1.075", "1.077", "1.080", "1.082", "1.085", "1.087", "1.090", "1.092", "1.095", "1.097", "1.100"};
        OGcombo.setItems(Items);
        OGcombo.setText("1.000");
        OGcombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
                Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
                DecimalFormat df1 = new DecimalFormat("#.####");
                mashAbvText.setText(String.valueOf(df1.format((og - tg) * 105 * 1.25)));
            }

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }
        });
    }

    private void createTGcombo() {
        TGcombo = new Combo(Distgroup, SWT.NONE);
        TGcombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"1.000", "1.002", "1.005", "1.007", "1.010", "1.012", "1.015", "1.017", "1.020", "1.022", "1.025", "1.0275", "1.030", "1.032", "1.035", "1.037", "1.040", "1.042", "1.045", "1.047", "1.050", "1.052", "1.055", "1.057", "1.060", "1.062", "1.065", "1.067", "1.070", "1.072", "1.075", "1.077", "1.080", "1.082", "1.085", "1.087", "1.090", "1.092", "1.095", "1.097", "1.100"};
        TGcombo.setItems(Items);
        TGcombo.setText("1.000");
        TGcombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
                Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
                DecimalFormat df1 = new DecimalFormat("#.####");
                mashAbvText.setText(String.valueOf(df1.format((og - tg) * 105 * 1.25)));
            }

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }
        });
    }

    private void createOgTempCombo() {
        ogTempCombo = new Combo(Distgroup, SWT.NONE);
        ogTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49"};
        ogTempCombo.setItems(Items);
        ogTempCombo.setText("1.000");
        ogTempCombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
                Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
                DecimalFormat df1 = new DecimalFormat("#.####");
                mashAbvText.setText(String.valueOf(df1.format((og - tg) * 105 * 1.25)));
            }

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }
        });
    }

    private void createTgTempCombo() {
        tgTempCombo = new Combo(Distgroup, SWT.NONE);
        tgTempCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49"};
        tgTempCombo.setItems(Items);
        tgTempCombo.setText("1.000");
        tgTempCombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {

            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Double og = TempCorrections.GetSG(Double.valueOf(OGcombo.getText()), ogTempCombo.getText());
                Double tg = TempCorrections.GetSG(Double.valueOf(TGcombo.getText()), tgTempCombo.getText());
                DecimalFormat df1 = new DecimalFormat("#.####");
                mashAbvText.setText(String.valueOf(df1.format((og - tg) * 105 * 1.25)));
            }

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }
        });
    }

    private void createFlotbrowser() {
        GridData gridData = new GridData();
        gridData.horizontalSpan = 2;
        gridData.verticalSpan = 6;
        Flotbrowser = new Browser(sShell, SWT.NONE);
        Flotbrowser.setUrl("C:\\WhiskeyData\\flot\\examples\\FlotPlot.html");
        Flotbrowser.setLayoutData(gridData);
        Flotbrowser.setSize(700, 370);
    }

    public void createTimeSpanCombo() {
        timeSpanCombo = new Combo(plotGroup, SWT.NONE);
        timeSpanCombo.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        String[] Items = {"5 min", "10 min", "20 min", "30 min", "45 min", "1 hr", "2 hr", "5 hr", "10 hr", "1 day", "2 days", "3 days", "4 days", "5 days", "6 days", "7 days", "8 days", "10 days", "30 days"};
        timeSpanCombo.setItems(Items);
        timeSpanCombo.setText("20 min");
        timeSpanCombo.select(3);
        timeSpanCombo.addSelectionListener(new org.eclipse.swt.events.SelectionListener() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                Data.timeSpan = timeSpanCombo.getText();
                String[] dummy1 = null;
                if (Flot.main(dummy1))
                    Flotbrowser.setUrl("C:\\WhiskeyData\\flot\\examples\\FlotPlot.html");
//                Flotbrowser.setUrl("C:\\WhiskeyData\\flot\\examples\\realtime.html");
            }

            public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
            }
        });
    }

    static String getTimeSpan() {
        Hashtable hashtable = new Hashtable();
        hashtable.put("5 min", "5"); //adding value to Hashtable
        hashtable.put("10 min", "10");
        hashtable.put("20 min", "20");
        hashtable.put("30 min", "30");
        hashtable.put("45 min", "45");
        hashtable.put("1 hr", "60");
        hashtable.put("2 hr", "120");
        hashtable.put("5 hr", "300");
        hashtable.put("10 hr", "600");
        hashtable.put("1 day", "1440");
        hashtable.put("2 days", "2880");
        hashtable.put("3 days", "4320");
        hashtable.put("4 days", "5760");
        hashtable.put("5 days", "7200");
        hashtable.put("6 days", "8640");
        hashtable.put("7 days", "10080");
        hashtable.put("8 days", "11520");
        hashtable.put("10 days", "14400");
        hashtable.put("30 days", "43200");
        String output = (String) hashtable.get(Data.timeSpan);
        return output;
    }

    private void createPlotGroup() {
        GridLayout gridLayout4 = new GridLayout();
        gridLayout4.numColumns = 2;
        plotGroup = new Group(sShell, SWT.NONE);
        plotGroup.setText("Plot Settings");
        plotGroup.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        plotGroup.setLayout(gridLayout4);
        text112 = new Text(plotGroup, SWT.NONE);
        createTimeSpanCombo();
        text112.setEnabled(false);
        text112.setText("Set Time Span for Plot:");
        text112.setEditable(false);
        text112.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        text112.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT));
        Label filler13 = new Label(plotGroup, SWT.NONE);
        plotRefreshbutton = new Button(plotGroup, SWT.NONE);
        plotRefreshbutton.setText("Refresh Plot");
        plotRefreshbutton.setFont(new Font(Display.getDefault(), "Segoe UI", 16, SWT.NORMAL));
        plotRefreshbutton
                .addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
                    public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
                        Data.timeSpan = timeSpanCombo.getText();
                        String[] dummy1 = null;
                        if (Flot.main(dummy1))
                            Flotbrowser.setUrl("C:\\WhiskeyData\\flot\\examples\\FlotPlot.html");
//                            Flotbrowser.setUrl("C:\\WhiskeyData\\flot\\examples\\realtime.html");

                    }
                });
    }

}
